﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Sales_Data : System.Web.UI.Page
{
    ZSql zs = new ZSql();
    Function f = new Function();
    protected void Page_Load(object sender, EventArgs e)
    {
        string txt = "";
        string sql = "";
        string id = Request.QueryString["id"].Trim();
        string ModelId = Request.QueryString["ModelId"].Trim();
        string type = Request.QueryString["type"].Trim();//按什么类型查询:1:代码 2:型号
        string where = "";
        if (type == "1" && !string.IsNullOrEmpty(id))//1:代码 
        {
            where = "ComodBarcode='" + id + "'";
        }
        else if (type == "2" && !string.IsNullOrEmpty(ModelId))//2:型号
        {
            where += "Specifications='" + ModelId + "'";
        }
        where += " order by StockId desc";
        if (!string.IsNullOrEmpty(where))
        {
            sql = "SELECT top 1 * FROM (select  a.*,(select top 1 Specifications from Specifications where SpecificationsId=a.ModelId) as Specifications,(select Units from Units where UnitsId=a.UnitId ) as Units, (select top 1 WarehouseName from CS_Warehouse where a.WarehouseId=WarehouseId) as WarehouseName,(select top 1 Brand from Brand where BrandId=a.BrandId)  as Brand,(select top 1 ComoditiesName from ComoditiesName where ComoditiesNameId=a.ComoditiesName) as Comodities  from  CS_Stock a  ) tblStock where typeStock!='工程机' and " + where;

            zs.Open(sql);
            if (zs.m_table.Rows.Count > 0)
            {
                txt = zs.m_table.Rows[0]["WarehouseName"].ToString() + "," + zs.m_table.Rows[0]["RestMoney"].ToString() + "," + zs.m_table.Rows[0]["WholeMoney1"].ToString() + "," + zs.m_table.Rows[0]["RetailMoney"].ToString() + "," + zs.m_table.Rows[0]["Brand"].ToString() + "," + zs.m_table.Rows[0]["Comodities"].ToString() + "," + zs.m_table.Rows[0]["Specifications"].ToString() + "," + zs.m_table.Rows[0]["Units"].ToString() + "," + zs.m_table.Rows[0]["ComodBarcode"].ToString() + "," + zs.m_table.Rows[0]["ComoditiesId"].ToString() + "," + zs.m_table.Rows[0]["ProcMoney"] + "," + zs.m_table.Rows[0]["typeStock"].ToString() + "," + zs.m_table.Rows[0]["WarehouseId"].ToString() + "," + zs.m_table.Rows[0]["ComoditiesType"].ToString() + "," + zs.m_table.Rows[0]["ActiveMoney"].ToString() + "," + f.getStock(zs.m_table.Rows[0]["ComodBarcode"].ToString(), "1");//f.getStock()通过编号求库存
            }
            zs.Close();
        }
        Response.Write(txt);
        Response.End();
    }
}
